package com.bishe.demo.controller;

import com.bishe.demo.pojo.Vip;
import com.bishe.demo.pojo.vo.Status;
import com.bishe.demo.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class VipController {

    @Autowired
    VipService vipService;
    @RequestMapping("tiaozhuanSelectVip")
    public String tiaozhuanSelectVip(HttpSession httpSession){

        List<Vip> vipList = vipService.selectVip();
        httpSession.setAttribute("vipList",vipList);
        return "selectVip";
    }

    @RequestMapping("tiaozhuanDeleteVip")
    public String tiaozhuanDeleteVip(HttpSession httpSession){

       List<Vip> vipList = vipService.selectVip();
       httpSession.setAttribute("deletVipId",vipList);
        return "deleteVip";
    }

    @RequestMapping("receiveVipId")
    public String receiveVipId(Integer vipId,HttpSession httpSession){

        Status status = vipService.deleteVipById(vipId);
        httpSession.setAttribute("deleteVipMsg",status.getMsg());

        return "deleteVipMsg";
    }

    @RequestMapping("tiaozhuanUpdate")
    public String tiaozhuanUpdate(HttpSession httpSession){

        List<Vip> list = vipService.selectVip();
        httpSession.setAttribute("updateVip",list);

        return "updateVip";
    }
    //接收更新的Vip信息

    @RequestMapping("updateVip")
    public String updateVip(Integer vipId,String vipName,HttpSession httpSession){

        Status status = vipService.updateVip(vipId,vipName);
        httpSession.setAttribute("updateById",status.getMsg());

        return "updateVipMsg";
    }
    @RequestMapping("tiaozhuanAddVip")
    public String tiaozhuanAddVip(){


        return "addVip";
    }
    //接收Vip添加信息
    @RequestMapping("receiveAddVip")
    public String receiveAddVip(String vipName,HttpSession httpSession){

        Status status = vipService.addVip(vipName);
        httpSession.setAttribute("addVipMsg",status.getMsg());

        return "addVipMsg";
    }
}
